package bite;

import java.util.Arrays;

/**
 * Creared with IntelliJ IDEA.
 * Description:奇数位上都是奇数或者偶数位上都是偶数
 * User:yxd
 * Date:2022-05-25
 * Time:17:59
 */
public class Day28_3 {
    public static void main(String[] args) {
        int[] arr = {1,8,6,2,3,7,5};
        reasonable(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void reasonable(int[] arr){
        int m = 0;//偶数位
        int n = 1;//奇数位
        while(m < arr.length && n < arr.length){
            while(m < arr.length && arr[m] % 2 == 0){
                m += 2;
            }
            while(n < arr.length && arr[n] % 2 == 1){
                n += 2;
            }
            if(m < arr.length && n < arr.length){
                int tmp = arr[m];
                arr[m] = arr[n];
                arr[n] = tmp;
            }
        }

    }
}
